package com.luber.web.controller.backstage;

import com.luber.backstage.domain.EticketVehicle;
import com.luber.backstage.service.IEticketVehicleService;
import com.luber.common.core.domain.entity.SysUser;
import com.luber.common.core.domain.model.LoginUser;
import com.luber.common.utils.ServletUtils;
import com.luber.common.utils.poi.ExcelUtil;
import com.luber.framework.web.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.luber.common.annotation.Log;
import com.luber.common.core.controller.BaseController;
import com.luber.common.core.domain.AjaxResult;
import com.luber.common.enums.BusinessType;
import com.luber.common.core.page.TableDataInfo;

import java.util.List;
import java.util.Map;

/**
 * 【请填写功能名称】Controller
 *
 * @author luber
 * @date 2021-03-22
 */
@RestController
@RequestMapping("/system/vehicle")
public class EticketVehicleController extends BaseController
{
    @Autowired
    private IEticketVehicleService eticketVehicleService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:vehicle:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam Map<String,Object> params)
    {
        startPage();
        List<EticketVehicle> list = eticketVehicleService.selectEticketVehicleList(params);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
    @PreAuthorize("@ss.hasPermi('system:vehicle:export')")
    @Log(title = "", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Map<String,Object> params)
    {
        List<EticketVehicle> list = eticketVehicleService.selectEticketVehicleList(params);
        ExcelUtil<EticketVehicle> util = new ExcelUtil<EticketVehicle>(EticketVehicle.class);
        return util.exportExcel(list, "vehicle");
    }

    /**
     * 获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:vehicle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(eticketVehicleService.selectEticketVehicleById(id));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('system:vehicle:add')")
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EticketVehicle eticketVehicle)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        // 用户信息
        SysUser user = loginUser.getUser();
        eticketVehicle.setCreateUser(user.getUserId());
        return toAjax(eticketVehicleService.insertEticketVehicle(eticketVehicle));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('system:vehicle:edit')")
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EticketVehicle eticketVehicle)
    {
        return toAjax(eticketVehicleService.updateEticketVehicle(eticketVehicle));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('system:vehicle:remove')")
    @Log(title = "", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eticketVehicleService.deleteEticketVehicleByIds(ids));
    }
}
